package com.mt.api.core.page;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.Objects;

/**
 * @Author: plover
 * @Date: 2020/07/09/3:13 下午
 * @Description:
 */
public class PageFactory {

    private static Integer DEFAULT_PAGE_SIZE = 20;
    private static Integer DEFAULT_PAGE_NUM = 1;

    public static Page defaultPage(int pageSize, int pageNum) {
        int limit = pageSize;
        int page = pageNum;
        return new Page(page, limit);
    }

    public static Page defaultPage(BasePage basePage) {
        int limit = Objects.nonNull(basePage) && Objects.nonNull(basePage.getPageSize()) ? basePage.getPageSize() : DEFAULT_PAGE_SIZE;
        int page = Objects.nonNull(basePage) && Objects.nonNull(basePage.getPageNum()) ? basePage.getPageNum() : DEFAULT_PAGE_NUM;
        return new Page(page, limit);
    }

}
